﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Data;

public class ChatPanel : MonoBehaviour {

    public InputField input;
    public Text chatText;
    public Button sendBtn;

    void Awake()
    {
        EventDispatcher.MessageHendler += OnMessage;
    }

    void OnDestroy()
    {
        EventDispatcher.MessageHendler -= OnMessage;
    }

    void Start()
    {
        sendBtn.onClick.AddListener(OnSendClick);
    }

    void OnSendClick()
    {
        string msg = input.text;

        Chat chat = new Chat();
        
        chat.msg = input.text;
        NetworkManager.Instance.Send(Protocal.Chat_CMD,ProtoHelper.Serialize(chat));
    }

    void OnMessage(Data.Chat msg)
    {
        chatText.text += msg + "\r\n";
    }

}
